/*
 * @Author: your name
 * @Date: 2020-07-20 15:40:49
 * @LastEditTime: 2020-11-11 16:26:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \BRSS-web-project\plugins\api.js
 */
// import { Loading } from 'element-ui'
// api.js
export default ({ app }, inject) => {
  // url : string, 服务器端url
  // data: Object, 请求的数据
  // isNotify: bool, 是否在右上角显示提示信息，默认'yes', 不显示传'no'
  inject('postService', async function(url, data, isNotify) {
    // 客户端请求，需要使用前缀/api/代理
    // console.log('window from remoteserver, ', app, inject)
    if (!process.server) {
      url = url
    }
    try {
      const result = await app.$axios.$post(url, data)
      if (!process.server && (!isNotify || isNotify !== 'no')) {
        console.debug('接口请求成功')
      }
      // loadingInstance.close() // 关闭笼罩层
      return result
    } catch (e) {}
  })

  inject('getService', async function(url, data, isNotify) {
    console.log(data)
    // 客户端请求，需要使用前缀/api/代理
    if (!process.server) {
      url = '/api/' + url
    }
    try {
      const result = await app.$axios.$get(url)
      if (!process.server && (!isNotify || isNotify !== 'no')) {
      }
      return result
    } catch (e) {}
  })
}
